from math import hypot


class Vector:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    # 表示
    def __repr__(self):
        return 'Vector(%r, %r)' % (self.x, self.y)

    # 求向量的绝对值
    def __abs__(self):
        return hypot(self.x, self.y)

    # 判断是否为非零向量
    def __bool__(self):
        return bool(self.x or self.y)

    # 向量相加
    def __add__(self, other):
        x = self.x + other.x
        y = self.y + other.y
        return Vector(x, y)

    # 标量乘法，标量scalar
    def __mul__(self, scalar):
        return Vector(self.x * scalar, self.y * scalar)


if __name__ == '__main__':
    v1 = Vector(2, 1)
    v2 = Vector(2, 4)
    print(v1.__repr__())
    print(v1.__bool__())
    vsum = v1.__add__(v2)
    print(vsum)
    print(vsum.__abs__())
    print(vsum.__mul__(5))